import { Language } from "../../../../../extend/language/Language";
import { ItemData } from "../../../resource/info/ItemData";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { MsgManager } from "../../../manager/MsgManager";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Global } from "../../../../../com/gengine/global/Global";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { BaseItem } from "../../common/BaseItem";
import { NumInput } from "../../common/NumInput";
type int = number;
//class ItemFeatureTips
    
    export  class ItemFeatureTips
    {
        

        /* internal  */static get htmlContent(): string
        {
            return "<font color=\'#ffffff\'>" + Language.getString(40041) + "</font><font color=\'#ff3c3c\'>" + Language.getString(40042) + "<font color=\'#ffffff\'>" + Language.getString(40043) + "</font>";
        }

        /* internal  */static get htmlTitle(): string
        {
            return "<font color=\'#f5ff00\'>" + Language.getString(40044) + "</font>";
        }

        public static destroyItem(arg1: ItemData): void
        {
            var itemData: ItemData;
            var closeAlert: Function;

            var loc1;
            closeAlert = null;
            itemData = arg1;
            closeAlert = (arg1: int): void
            {
                if (arg1 == Alert.OK) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Destroy, itemData));
                }
                return;
            }
            if (!itemData) 
            {
                return;
            }
            Alert.show(htmlContent, null, Alert.OK | Alert.CANCEL, null, closeAlert);
            return;
        }

        public static splitTip(arg1: ItemData): void
        {
            var itemData: ItemData;
            var splitWindow: BaseWindow;
            var bg: ScaleBitmap;
            var textField: GTextFiled;
            var textInput: GTextInput;
            var btnOK: GButton;
            var btnCancel: GButton;
            var SplitHandler: Function;
            var CloseHandler: Function;

            var loc1;
            splitWindow = null;
            bg = null;
            textField = null;
            textInput = null;
            SplitHandler = null;
            CloseHandler = null;
            itemData = arg1;
            SplitHandler = (arg1: Object /* flash.events.MouseEvent */): void
            {
                var loc1=int(textInput.text);
                if (loc1 > 0 && loc1 < itemData.itemAmount) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Split, {"uid": itemData.uid, "amount": loc1}));
                    splitWindow.hide();
                }
                return;
            }
            CloseHandler = (arg1: Object /* flash.events.MouseEvent */): void
            {
                splitWindow.hide();
                return;
            }
            if (!itemData) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40045));
                return;
            }
            if (itemData.itemAmount <= 1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40046));
                return;
            }
            if (ItemsUtil.isTaskItem(itemData)) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40047));
                return;
            }
            splitWindow = new BaseWindow();
            splitWindow.titleHeight = 26;
            splitWindow.width = 240;
            splitWindow.height = 150;
            splitWindow.x = (Global.stage.stageWidth - 240) / 2;
            splitWindow.y = (Global.stage.stageHeight - 130) / 2;
            splitWindow.title = GlobalClass.getBitmap("Title_Tips");
            bg = ResouceConst.getScaleBitmap("WindowCenterB");
            bg.x = 17;
            bg.y = 37;
            bg.setSize(206, 102);
            splitWindow.addChild(bg);
            textField = new GTextFiled();
            textField.x = 45;
            textField.y = 47;
            textField.selectable = false;
            textField.width = 150;
            textField.height = 20;
            textField.htmlText = "<font color=\'#ffffff\' size=\'13\'>" + Language.getString(40048) + "</font>";
            splitWindow.addChild(textField);
            textInput = new GTextInput();
            textInput.width = 133;
            textInput.height = 20;
            textInput.x = 50;
            textInput.y = 73;
            textInput.styleName = "GTextInput";
            textInput.restrict = "0-9";
            textInput.text = "1";
            splitWindow.addChild(textInput);
            btnOK = new GButton();
            btnOK.label = Language.getString(40049);
            btnOK.styleName = "Button";
            btnOK.width = 47;
            btnOK.height = 22;
            btnOK.x = 45;
            btnOK.y = 103;
            btnOK.addEventListener(flash.events.MouseEvent.CLICK, SplitHandler);
            splitWindow.addChild(btnOK);
            btnCancel = new GButton();
            btnCancel.label = Language.getString(40050);
            btnCancel.styleName = "Button";
            btnCancel.width = 47;
            btnCancel.height = 22;
            btnCancel.x = 145;
            btnCancel.y = 103;
            btnCancel.addEventListener(flash.events.MouseEvent.CLICK, CloseHandler);
            splitWindow.addChild(btnCancel);
            splitWindow.show();
            Global.stage.focus = textInput;
            return;
        }

        public static bulkUse(arg1: ItemData, arg2: Function=null): void
        {
            var itemData: ItemData;
            var callback: Function=null;
            var bulkWindow: BaseWindow;
            var bg: ScaleBitmap;
            var bgBmp: Object /* flash.display.Bitmap */;
            var propItem: BaseItem;
            var textField: GTextFiled;
            var numInput: NumInput;
            var btnOK: GButton;
            var btnCancel: GButton;
            var BulkHandler: Function;
            var CloseHandler: Function;

            var loc1;
            bulkWindow = null;
            numInput = null;
            BulkHandler = null;
            CloseHandler = null;
            itemData = arg1;
            callback = arg2;
            BulkHandler = (arg1: Object /* flash.events.MouseEvent */): void
            {
                var loc1=numInput.currentNum;
                if (loc1 > 0 && loc1 <= itemData.itemAmount) 
                {
                    if (callback == null) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_BulkUse, {"itemData": itemData, "amount": loc1}));
                    }
                    else 
                    {
                        callback(itemData, loc1);
                    }
                    bulkWindow.hide();
                }
                return;
            }
            CloseHandler = (arg1: Object /* flash.events.MouseEvent */): void
            {
                bulkWindow.hide();
                return;
            }
            if (!itemData) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40051));
                return;
            }
            if (ItemsUtil.isTaskItem(itemData)) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40052));
                return;
            }
            if (ItemsUtil.isFlyWingProp(itemData)) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FashionFlyWingGoUpgradeLvBulk, itemData));
                return;
            }
            bulkWindow = new BaseWindow();
            bulkWindow.titleHeight = 25;
            bulkWindow.width = 240;
            bulkWindow.height = 145;
            bulkWindow.title = Language.getString(40053);
            bg = ResouceConst.getScaleBitmap("WindowCenterB");
            bg.x = 12;
            bg.y = 37;
            bg.setSize(215, 98);
            bulkWindow.addChild(bg);
            bgBmp = GlobalClass.getBitmap("PackItemBg");
            bgBmp.x = 24;
            bgBmp.y = 45;
            bulkWindow.addChild(bgBmp);
            propItem = new BaseItem();
            propItem.isDragAble = false;
            propItem.setSize(36, 36);
            propItem.label = "";
            propItem.move(25, 46);
            propItem.amount = 1;
            bulkWindow.addChild(propItem);
            propItem.itemData = itemData;
            textField = new GTextFiled();
            textField.x = 73;
            textField.y = 42;
            textField.selectable = false;
            textField.width = 150;
            textField.height = 20;
            textField.htmlText = "<font color=\'#ffffff\' size=\'13\'>" + Language.getString(40054) + "</font>";
            bulkWindow.addChild(textField);
            numInput = new NumInput();
            numInput.maxNum = itemData.itemAmount;
            numInput.x = 80;
            numInput.y = 68;
            bulkWindow.addChild(numInput);
            btnOK = new GButton();
            btnOK.label = Language.getString(40049);
            btnOK.styleName = "Button";
            btnOK.width = 49;
            btnOK.height = 28;
            btnOK.x = 45;
            btnOK.y = 95;
            btnOK.addEventListener(flash.events.MouseEvent.CLICK, BulkHandler);
            bulkWindow.addChild(btnOK);
            btnCancel = new GButton();
            btnCancel.label = Language.getString(40050);
            btnCancel.styleName = "Button";
            btnCancel.width = 49;
            btnCancel.height = 28;
            btnCancel.x = 145;
            btnCancel.y = 95;
            btnCancel.addEventListener(flash.events.MouseEvent.CLICK, CloseHandler);
            bulkWindow.addChild(btnCancel);
            bulkWindow.show();
            bulkWindow.x = Global.stage.mouseX - (btnOK.x + btnOK.width / 2);
            bulkWindow.y = Global.stage.mouseY - (btnOK.y + btnOK.height / 2);
            return;
        }
    }
